package com.xiaoran.client;

import com.xiaoran.client.cache.ServiceRouteCache;
import com.xiaoran.client.proxy.ServiceProxyManager;
import com.xiaoran.client.run.RpcRequestManager;
import com.xiaoran.client.run.RpcRequestPool;
import com.xiaoran.client.zk.ServicePullManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RpcClientRunner {
    @Autowired
    private RpcRequestPool rpcRequestPool;
    @Autowired
    private ServiceRouteCache serviceRouteCache;
    @Autowired
    private ServicePullManager servicePullManager;
    @Autowired
    private ServiceProxyManager serviceProxyManager;
    
    public void run() {
        //启动RPC管理器
        RpcRequestManager.startRpcRequestManager(rpcRequestPool, serviceRouteCache);
        //从zookeeper中获取服务提供者
        servicePullManager.pullServiceFromZK();
        //为拥有@RpcClient注解的服务创建代理
        serviceProxyManager.initServiceProxyInstance();
    }
}
